<template>
  <el-card class="box-card">
    <el-col :span="24" class="toolbar" v-if="hasAddPermission">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
          <el-input v-model="searchName" placeholder="名称"></el-input>
        </el-form-item>
        <el-form-item >
          <el-button @click="handleSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <el-table :data="page.records" highlight-current-row stripe border v-loading="listLoading" style="width: 100%;">
      <el-table-column prop="name" label="名称" ></el-table-column>
      <el-table-column prop="address" label="地址"  ></el-table-column>
      <el-table-column prop="cityName" label="所在城市名" ></el-table-column>
      <el-table-column prop="unitFreight" label="每公斤运费(元)" ></el-table-column>
      <el-table-column label="操作" width="80">
        <template scope="scope">
          <el-tooltip content="编辑配销中心" placement="top">
          <el-button icon="edit" v-if="hasEditPermission" type="primary" size="mini" @click="handleEdit"></el-button>
              
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-col :span="24" class="toolPage">
      <el-button type="primary" @click="handleAdd">添加配送中心</el-button>
      <el-pagination :current-page="page.current" :page-sizes="[10, 20, 50, 100]" :page-size="page.size"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="page.total" style="float:right"
                     @size-change="handleSizeChange"
                     @current-change="handlePageChange">
      </el-pagination>
    </el-col>
  </el-card>
</template>

<script>

	import * as Auth from 'common/auth'

  export default {
    created() {
      this.loadGridData()
    },
    data() {
      return {
        page: {
          total: 0,
          current: 1,
          size: 10,
          records: []
        },
        searchName:'',
				editFormVisible:false,//编辑界面显是否显示
				editFormTitle:'编辑',//编辑界面标题
				listLoading:true
     	}
    },
		computed: {
			hasAddPermission: () => Auth.hasPermission('admins:add'),
			hasEditPermission: () => Auth.hasPermission('admins:edit')
		},
    methods: {
			handleSizeChange(size) {
				this.page.size = size
				this.loadGridData()
			},
			handlePageChange(current) {
				this.page.current = current
				this.loadGridData()
			},
			loadGridData() {
			  this.listLoading = true;
				let param = {
					pageSize: this.page.size,
					page: this.page.current,
					searchName: this.searchName
				}
				this.axios.get("/stock_locations", {params: param}).then(response => {
					this.page = response.data
					this.listLoading = false
				})
			},
			handleAdd(){
				this.$router.push('/stock_locations/new')
			},
			handleEdit(row) {
				this.$router.push(`/stock_locations/${row.id}/edit`)
			},
			handleSearch(){
			this.loadGridData()
			}
    }
  }
</script>

<style>

</style>
